<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="<?php echo BASEURL; ?>resources/javascript/extjs/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="<?php echo BASEURL; ?>resources/css/login.css" />
<script src="<?php echo BASEURL;?>resources/javascript/extjs/ext-all.js"></script> 
<script src="<?php echo BASEURL;?>resources/javascript/extjs/locale/ext-lang-zh_CN.js" type="text/javascript"></script>

  <div id="x-loading-mask" style="width:100%; height:100%; background:#FFF; position:absolute; z-index:20000; left:0; top:0;">&#160;</div>
  <div id="x-loading-panel" style="position:absolute;left:40%;top:40%;border:1px solid #9c9f9d;padding:2px;background:#d1d8db;width:300px;text-align:center;z-index:20001;">
    <div class="x-loading-panel-mask-indicator" style="border:1px solid #c1d1d6;color:#666;background:white;padding:10px;margin:0;padding-left: 20px;height:130px;text-align:left;">
      <img class="x-loading-panel-logo" style="display:block;margin-bottom:15px;" src="<?php echo BASEURL;?>resources/images/logo.jpg" />
      <img src="<?php echo BASEURL;?>resources/images/loading.gif" style="width:16px;height:16px;vertical-align:middle" />&#160;
      <span id="load-status"><?php echo  'init_system'; ?></span>
      <div style="font-size:10px; font-weight:normal; margin-top:15px;">Copyright &copy; Web Control Center</div>
    </div>
  </div> 
  
  <div id="x-login-panel">
    <img src="<?php echo BASEURL;?>resources/images/s.gif" class="login-logo abs-position" />
    
    <div class="login-features abs-position">
      <p> HYD企业管理平台 </p>
      <p align="justify"> 专业CRM，为用户提供全新的操作体验。</p>
    </div>
    
    <img src="<?php echo BASEURL;?>resources/images/s.gif" class="login-screenshot abs-position" />
    
    <span class="login-supported abs-position">
      <b>支持浏览器</b><br /><br />
      &nbsp;&nbsp;<a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="_blank">Internet Explorer 8+</a><br />
      &nbsp;&nbsp;<a href="https://www.google.com/intl/zh-CN/chrome/browser/" target="_blank">Google Chrome </a>
    </span>
  
    <div id="x-login-form" class="x-login-form abs-position"></div>
  </div>

<script type="text/javascript">
Ext.onReady(function(){
    Ext.BLANK_IMAGE_URL = '<?php echo BASEURL; ?>resources/images/s.gif';
    Ext.EventManager.onWindowResize(centerPanel);
      
    var loginPanel = Ext.get("x-login-panel");
    centerPanel();
    Ext.namespace("Hydcrm");

    var txtUserName = null;
    var frmlogin = Ext.create('Ext.form.Panel', {
      bodyPadding: 5,
      width: 335,
      url: '<?php echo BASEURL; ?>index.php/login/checklogin',
      layout: 'anchor',
      defaults: {
        anchor: '100%'
      },
      defaultType: 'textfield',
      items: [
        txtUserName = new Ext.form.TextField({
          name: 'username', 
          fieldLabel: '用户名：', 
          labelSeparator: ' ', 
          allowBlank:false,
          blankText: '用户名不合法',
          listeners: {
            specialkey: function(field, e) {
              if (e.getKey() == e.ENTER) {
                login();
              }
            }
          }
        }),
        {
          name: 'password', 
          fieldLabel: '密码：', 
          inputType: 'password', 
          labelSeparator: ' ', 
          allowBlank:false,
          blankText: '密码不合法',
          listeners: {
            specialkey: function(field, e) {
              if (e.getKey() == e.ENTER) {
                login();
              }
            }
          }
        }
      ],
      buttons: [{
        text: '登录',
        handler: login, 
        scope: this
      }],
        listeners : {
            render: function() {
                txtUserName.focus(false, true);
            }
        },
        renderTo: 'x-login-form'
    });
      
    function centerPanel(){
        var xy = loginPanel.getAlignToXY(document, 'c-c');
        positionPanel(loginPanel, xy[0], xy[1]);
    }
      
    function login() {
        frmlogin.form.submit({
            waitMsg : '正在登录......',
            success: function (form, action) { //alert(action.result.feedback);
                window.location = '<?php echo  BASEURL; ?>'+'index.php';
            },
            failure: function (form, action) {
                if (action.failureType != 'client') {
                    Ext.Msg.alert('登录失败', action.result.feedback);
                }
            },
            scope: this
        });
    }
      
    function positionPanel(el, x, y){
        if(x && typeof x[1] == 'number') {
            y = x[1];
            x = x[0];
        }
        el.pageX = x;
        el.pageY = y;
        if(x === undefined || y === undefined){ // cannot translate undefined points
            return;
        }
        if(y < 0) { 
            y = 10;
        }
        var p = el.translatePoints(x, y);
        el.setLocation(p.left, p.top);
        return el;
    }
      
    function removeLoadMask() {
        var loading = Ext.get('x-loading-panel');
        var mask = Ext.get('x-loading-mask');
        loading.hide();
        mask.hide();
    }
      
    removeLoadMask(); 
});  
    
  </script>